import java.util.Scanner;

public class test {
    public static void reverse(char[] chars, int l, int r) {

        while (l <= r) {
            char temp = chars[l];
            chars[l] = chars[r];
            chars[r] = temp;
            l++;
            r--;
        }
    }
    public static char[] Func(String str, int index) {
        char[] chars = str.toCharArray();
        reverse(chars, 0, index - 1);
        reverse(chars, index, chars.length - 1);
        reverse(chars, 0, chars.length - 1);
        return chars;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        int index = scanner.nextInt();
        char[] ret = Func(str,index);
        for (int i = 0; i < ret.length; i++) {
            System.out.print(ret[i] + " ");
        }
    }
}
